Introduce key/value map bench #1121
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Two new benchmarks:
key_value_map
for evaluating different implementation choicesspan_builder
to focus on performance analysis ofSpanBuilder
Overview
There are four implementations considered:
EvictedHashMap
: currently used bySpanData
to carry span attributesIndexMap
: currently used bySpanBuilder
to carry span attributes (in anOrderMap
)OneVec
:Vec<(Key, Value>)
where no hashing or duplicate key detection takes placeTwoVec
: aVec<Key>
and aVec<Value>
, linked by shared indices, where no hashing or duplicate key detection takes placeThere are two main operations to consider for each implementation:
lookup
: find two attributes in "the map"populate
: populaten
(2, 8, or 32) attributes in the maplookup
approximates what a sampling decision might do in consulting specific keys present in theSpanBuilder
. Its performance looks like the following: (Note, theVec
based implementations are pessimized for worst-case, finding the last two attributes in the map.)OneVec
beatsIndexMap
for 2 and 8 attributes in the map, but loses for 32 attributes.populate
approximates what anyone who wants to create aSpan
must pay to get attributes into theSpanBuilder
. Its performance looks like the following:As expected, populating hash maps is a lot more expensive than populating vectors, but that's the cost of detecting duplicates.
Learnings
Knowing that we have to both
populate
andlookup
when creating aSpan
, it's useful to see both together:Now we see that
OneVec
beatsIndexMap
for all cases, and is more than twice as fast asIndexMap
for 32 attributes.So this PR is meant to do three things:
SpanBuilder
that ends up producing aSpan
that is non-recording pay for indexing that will never get used.